package com.seleniti.enpareja.controller.model.integration.database.domain;

import java.math.BigDecimal;
import java.util.Date;

import javax.jdo.annotations.Column;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Version;
import javax.jdo.annotations.VersionStrategy;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Version(column = "version", strategy = VersionStrategy.VERSION_NUMBER, extensions = { @Extension(vendorName = "datanucleus", key = "field-name", value = "version") })
public class SharedExpense {

	public enum MadeBy {
		MEMBER_1, MEMBER_2;
	}

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String sharedExpenseId;

	@Column(allowsNull = "false")
	@NotNull
	private Couple couple;

	@Column(length = 150)
	@Size(max = 150)
	private String text;

	@Column
	private Date date;

	@Column(allowsNull = "false")
	@NotNull
	private Date savedAt;

	@Column
	private MadeBy madeBy;

	@Column
	private BigDecimal amount;

	@Column
	private boolean shared = true;

	protected long version;

	public SharedExpense() {

	}

	public Couple getCouple() {
		return couple;
	}

	public void setCouple(Couple couple) {
		this.couple = couple;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public MadeBy getMadeBy() {
		return madeBy;
	}

	public void setMadeBy(MadeBy madeBy) {
		this.madeBy = madeBy;
	}

	public String getSharedExpenseId() {
		return sharedExpenseId;
	}

	public void setSharedExpenseId(String sharedExpenseId) {
		this.sharedExpenseId = sharedExpenseId;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public boolean isShared() {
		return shared;
	}

	public void setShared(boolean shared) {
		this.shared = shared;
	}

	public Date getSavedAt() {
		return savedAt;
	}

	public void setSavedAt(Date savedAt) {
		this.savedAt = savedAt;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("SharedExpense [sharedExpenseId=").append(sharedExpenseId).append(", couple=").append(couple)
				.append(", text=").append(text).append(", date=").append(date).append(", savedAt=").append(savedAt)
				.append(", madeBy=").append(madeBy).append(", amount=").append(amount).append(", shared=")
				.append(shared).append(", version=").append(version).append("]");
		return builder.toString();
	}

}
